import domain.Student;
import factory.FKSqlSessionFactory;
import mapper.UserMapper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Scanner;

/**
 * @pakager_name:PACKAGE_NAME
 * @description:
 * @author: 周铖鑫
 * @time: 2020/12/7 21:14
 */
public class SelectStudentTestByInterface {
    public static void main(String args[]) {
        SqlSession sqlSession = null;
        try{
            //一对多映射
            sqlSession= FKSqlSessionFactory.getSqlSession();
            //使用接口的代理对象
            UserMapper userMapper=sqlSession.getMapper(UserMapper.class);
            Scanner scanner=new Scanner(System.in);
            System.out.println("请输入要查询的clazz_id（查询clazz_id的学生)");
            int input=scanner.nextInt();
            //调用接口方法
            List<Student>studentList=userMapper.selectStudentWithId(input);
            //System.out.println(student.getName());
//            List<Student> studentList=sqlSession.selectList("mapper.UserMapper.selectStudent");
            studentList.forEach(student -> System.out.println("clazz_id为"+input+"的学生姓名"+student.getName()));
            sqlSession.commit();
        }catch (Exception e){
            sqlSession.rollback();
            e.printStackTrace();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }
}

